﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace VikingArcade_v2._0
{
    public class MenuUserInterface : UserInterface
    {
        private readonly string[] menuCaptions = 
        {
            "Pojedyncza gra",
            "Kampania",
            "Opcje",
            "Wyjscie"
        };

        private Panel background;
        private Menu menu;

        protected override void InitializeControls()
        {
            base.InitializeControls();

            //------------------------------------------------------------------------
            //BackgroundPanel
            //------------------------------------------------------------------------

            background = new Panel();
            background.BackgroundTexture = GameContentManager.GetTexture("loadingScreen");
            background.Size = new Point(DisplayController.GraphicsDevice.PresentationParameters.BackBufferWidth,
                                        DisplayController.GraphicsDevice.PresentationParameters.BackBufferWidth *
                                        background.BackgroundTexture.Height / background.BackgroundTexture.Width);
            background.Position = new Point(0,
                                            (DisplayController.GraphicsDevice.PresentationParameters.BackBufferHeight -
                                             background.Size.Y) / 2);
            background.Anchor = Anchor.StretchWidth;
            controls.Add(background);

            //------------------------------------------------------------------------
            //Menu
            //------------------------------------------------------------------------

            menu = new Menu();
            menu.Position = new Point(0,0);
            menu.Size = new Point(DisplayController.GraphicsDevice.PresentationParameters.BackBufferWidth,                                                                                              DisplayController.GraphicsDevice.PresentationParameters.BackBufferHeight);
            menu.ElementColor = Color.DarkBlue;
            menu.SelectedElementColor = Color.Yellow;
            menu.Anchor = Anchor.Stretch;

            SpriteFont font = GameContentManager.GetFont("MenuFont");
            foreach (string menuCaption in menuCaptions)
            {
                TextBox textBox = new TextBox();
                textBox.Text = menuCaption;
                textBox.Font = font;
                textBox.Size = new Point(Convert.ToInt32(Math.Ceiling(font.MeasureString(menuCaption).X)),
                                         Convert.ToInt32(Math.Ceiling(font.MeasureString(menuCaption).Y)));
                menu.AddMenuElement(textBox);
            }
            menu.MenuElementClicked += new Menu.OnElementClick(MenuElementClicked);
            controls.Add(menu);
        }

        void MenuElementClicked(string ElementCaption)
        {
            switch (ElementCaption)
            {
                case "Pojedyncza gra":
                    Router.GameState = GameState.NewMission;
                    break;
                case "Kampania":
                    Router.GameState = GameState.NewCampaign;
                    break;
                case "Opcje":
                    Router.GameState = GameState.Options;
                    break;
                case "Wyjscie":
                    Router.GameState = GameState.Quit;
                    break;
            }
        }
    }
}
